import React from 'react'
import { connect } from 'dva'
import List from './List'
import Menu from './Menu'
import New from './New'
import CodeConfig from './codeConfig'

const ConfigManager = ({location,dispatch,configManager,loading}) =>{
	const {list,pagination1,showMenu,info,codeList} = configManager
	const menuProps = {
		changeMenu(payload){
			dispatch({
				type:'configManager/changeMenu',
				payload:payload
			})
		},
		showConfig(payload){
			dispatch({
				type:'configManager/showConfig',
				payload:payload
			})
		},
		getCode(){
			dispatch({
				type:"configManager/getCodeList"
			})
		}
	}
	const listProps = {
		list,
		pagination1,
		onDelete(params){
			dispatch({
				type:'configManager/delete',
				payload:{
					...params
				}
			})
		},
		changeMenu(payload){
			dispatch({
				type:'configManager/changeMenu',
				payload:payload
			})
		},
		showDetails(id){
			dispatch({
				type:'configManager/info',
				payload:{
					id:id
				}
			})
		}
	}
	const newProps = {
		info,
		onComponent(params){
			dispatch({
				type:'configManager/newFile',
				payload:{
					...params
				}
			})
		},
		changeMenu(payload){
			dispatch({
				type:'configManager/changeMenu',
				payload:payload
			})
		},
		onUpdate(payload){
			dispatch({
				type:'configManager/update',
				payload:payload
			})
		}
	}
	const CodeProps = {
		codeList,
		changeMenu(payload){
			dispatch({
				type:'configManager/changeMenu',
				payload:payload
			})
		},
		newCode(payload){
			dispatch({
				type:'configManager/newCode',
				payload:payload
			})
		},
		updateCode(payload){
			dispatch({
				type:"configManager/updateCode",
				payload:payload
			})
		}
		
	}
	
	return(
		<div className='content-inner' style={{backgroundColor:'transparent',padding:0}}>
			{showMenu == '1'?
				<Menu {...menuProps}/>:
			showMenu == '2'?
				<List {...listProps}/>: 
			showMenu == '3'?
				<New {...newProps}/>:
				<CodeConfig {...CodeProps}/>
			}
			
		</div>
	)
}

export default connect(({ configManager,loading}) =>({configManager,loading}))(ConfigManager)
